import { commonLs } from '../../utils/common'
import { TOGGLE_COLLAPSED_TYPE } from './type'

const reducer = (
  /* eslint-disable-next-line */
  state = {
    collapsed: (() => {
      const [err, collapsed] = commonLs.get('collapsed')
      return err ? false : collapsed
    })(),
  },
  action,
) => {
  const newState = { ...state }
  const { type, payload } = action
  switch (type) {
    case TOGGLE_COLLAPSED_TYPE:
      newState.collapsed = !newState.collapsed
      break;
    default:
      break;
  }
  return newState
}
export default reducer
